package com.autologistics.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;

import com.autologistics.model.Goodskind;
import com.autologistics.service.GoodskindService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class GoodskindAction extends ActionSupport implements ModelDriven<Goodskind>{
	GoodskindService goodskindService;
	private Goodskind goodskind=new Goodskind();
	private List<Goodskind> goodskindList;
	
	HttpServletResponse response=ServletActionContext.getResponse();
	

	
	
	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}



	public List<Goodskind> getGoodskindList() {
		return goodskindList;
	}



	public void setGoodskindList(List<Goodskind> goodskindList) {
		this.goodskindList = goodskindList;
	}



	public GoodskindService getGoodskindService() {
		return goodskindService;
	}



	public void setGoodskindService(GoodskindService goodskindService) {
		this.goodskindService = goodskindService;
	}



	@Override
	public Goodskind getModel() {
		// TODO Auto-generated method stub
		return this.goodskind;
	}
	
	/**
	 * to get list of all Goodskind.
	 * @return
	 */
	public String listGoodskind(){
		List<Goodskind> getGoodskindList=goodskindService.listAll();
		JSONArray jsonArray = null;
		jsonArray=JSONArray.fromObject(getGoodskindList);
		response.setContentType("text/html;charset=UTF-8");
		try {
			response.getWriter().print(jsonArray.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	
	

}
